//商品相关方法

const {
    execSQL
} = require('../db/mysql')

//商品数据
const getGood = ({id}) => {
    let sql = `select data from goods where id = '${id}'`;
    return execSQL(sql).then((res) => {
        return res[0].data ? JSON.parse(res[0].data):false;
    }).catch(e => {
        return false;
    })
}

const getCartInfo = ({id}) => {
    let sql = `select data from cart_info where good_id = '${id}'`;
    return execSQL(sql).then((res) => {
        return res[0].data ? JSON.parse(res[0].data):false;
    }).catch(e => {
        return false;
    })
}

const searchGoods = ({key,limit}) => {
    

    let sql = `select data from goods where title LIKE '%${key}%' limit ${limit}, 10`;
    return execSQL(sql).then((res) => {
        return res;
    }).catch(e => {
        return false;
    })
}





module.exports = {
    getGood,
    getCartInfo,
    searchGoods
}